package xyz.naokeziteng.leetcode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author hawk
 * @date 2022/7/28
 * @desc
 **/
public class MyQueue {

    private Deque<Integer> enter;
    private Deque<Integer> output;

    public MyQueue() {
        enter = new LinkedList<>();
        output = new LinkedList<>();
    }

    public void push(int x) {
        int size = output.size();
        for (int i = 0; i < size; i++) {
            enter.offerLast(output.removeLast());
        }
        output = new LinkedList<>();
        output.offerLast(x);
        for (int i = 0; i < size; i++) {
            output.offerLast(enter.removeLast());
        }
        enter = new LinkedList<>();

    }

    public int pop() {
        return output.removeLast();
    }

    public int peek() {
        return output.peekLast();
    }

    public boolean empty() {
        return output.isEmpty();
    }


    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        myQueue.push(3);
        myQueue.push(4);
        myQueue.push(5);
        myQueue.push(6);
        myQueue.push(7);
        myQueue.push(8);
        myQueue.push(9);
        myQueue.push(10);
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.pop());
    }
}
